<%@ page import="bid.dao.UserDao" %>
<%@ page import="bid.dao.impl.UserDaoImpl" %>
<%@ page import="bid.entity.User" %>
<%@ page import="java.util.List" %>
<%@ page import="bid.util.StringUtils" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理员信息</title>
    <script>
        function  gotoBd() {
            window.location="https://www.baidu.com";
        }
    </script>
</head>
<body>
<%--<%@include file="checkLogin.jsp"%>--%>
<%
    UserDao userDao = new UserDaoImpl();
    //int pageNo=Integer.parseInt(request.getParameter("pageNo"));
    String name=StringUtils.trim(request.getParameter("name"));
    String username=StringUtils.trim(request.getParameter("username"));
    Date start=StringUtils.toDate(request.getParameter("start"));
    Date end=StringUtils.toDate(request.getParameter("end"));
    int pageNo = StringUtils.toInt(request.getParameter("pageNo"), 1);
    int pageSize=10;
    List<User> users = userDao.search(pageNo, pageSize, name, username, start, end);

    long total=userDao.searchTotal(name,username,start,end);

    long pageNums=total/pageSize+(total%pageSize==0?0:1);//求页数

%>
<p style="text-align: right">
    <a href="addUser.jsp">新增一个管理员</a>
</p>
<p>
    <form method="get" action="users.jsp">
    <div>
        <input type="text" name="name" value="<%=name%>" placeholder="姓名查找"/>
        <input type="text" name="username" value="<%=username%>" placeholder="登录名名查找"/>
        入职时间：从<input type="date" name="start" value="<%=StringUtils.toStr(start)%>" placeholder="时间"/>-
        到<input type="date" name="end" value="<%=StringUtils.toStr(end)%>" placeholder="时间"/>
        <input type="submit" value="搜索"/>

       <%-- <input type="button" value="去百度" onclick="gotoBd()"/>--%>
    </div>
</form>
</p>
<table border="1" cellpadding="0" cellspacing="0">
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>手机号</th>
        <th>登录名</th>
        <th>入职时间</th>
        <th>操作</th>
    </tr>
    <%
        for (User u : users) {
    %>
    <tr>
        <td><%=u.getId()%>
        </td>
        <td><%=u.getName()%>
        </td>
        <td><%=u.getTelephone()%>
        </td>
        <td><%=u.getUsername()%>
        </td>
        <td><%=u.getEnterdate()%>
        </td>
        <td>
            <a onclick="return confirm('真的要删除码？')" href="delUser.jsp?id=<%=u.getId()%>">删除</a>
            <a href="updateUser.jsp?id=<%=u.getId()%>">修改</a>
        </td>
    </tr>
    <%}%>
</table>
<p style="text-align: center">
    <a href="users.jsp?pageNo=1&name=<%=name%>&username=<%=username%>&start=<%=StringUtils.toStr(start)%>&end=<%=StringUtils.toStr(end)%>">第一页</a>
    <%
        if(pageNo>1){
    %>
    <a href="users.jsp?pageNo=<%=pageNo-1%>&name=<%=name%>&username=<%=username%>&start=<%=StringUtils.toStr(start)%>&end=<%=StringUtils.toStr(end)%>">上一页</a>
   <%}%>
     <input style="width:40px" value="<%=pageNo%>"  type="number" id="go" name="goto" min="1" max="<%=pageNums%>"/>
     <input type="button" value="Go" onclick="gotoPage()"/>
    <%
        if(pageNo<pageNums){
    %>
    <a href="users.jsp?pageNo=<%=pageNo+1%>&name=<%=name%>&username=<%=username%>&start=<%=StringUtils.toStr(start)%>&end=<%=StringUtils.toStr(end)%>">下一页</a>
    <%}%>
    <a href="users.jsp?pageNo=<%=pageNums%>&name=<%=name%>&username=<%=username%>&start=<%=StringUtils.toStr(start)%>&end=<%=StringUtils.toStr(end)%>">最后一页</a>
</p>
<script>
    function gotoPage() {
        let p=document.getElementById("go").value;
        window.location="users.jsp?pageNo="+p+"&name=<%=name%>&username=<%=username%>&start=<%=StringUtils.toStr(start)%>&end=<%=StringUtils.toStr(end)%>";
    }
</script>
</body>
</html>
